{% extends 'base.html' %}

{% block content%}
    <div class="grid_12">
    {% if form.errors %}
        <ul>
        {% for field in form %}
            {% if field.errors %}
                <li>
                    <strong>{{ field.label }}</strong> - <strong class="error">{{ field.errors|striptags }}</strong>
                </li>
            {% endif %}
        {% endfor %}
        </ul>
    {% endif %}
    </div>
    <div class="clear"></div>
    <div class="grid_9">
<form enctype="multipart/form-data" action="" method="post"><div id="csrf_token">{% csrf_token %}</div>
    <table class="forma color1">
        <tr><td width="160"><strong>Разновидность тренинга:</strong></td><td>{{ form.kind }}</td></tr>
        <tr><td width="160"><strong>Название тренинга:</strong></td><td>{{ form.title }}</td></tr>
        {% if form.direction  %}<tr><td width="160"><strong>Направление повышения квалификации:</strong></td>
            <td>{{ form.direction }}</td></tr>
        {% endif %}
        <tr><td width="160"><strong>Примечание:</strong></td><td>{{ form.note }}</td></tr>
        <tr><td width="160" style="vertical-align:top;"><strong>Сотрудники:</strong></td>
            <td>
                {% for u in units %}
                    {% if argument == "workers" %}
                        {% regroup u.get_employees_work by actual_unit as e_list %}
                    {% else %}
                        {% regroup u.get_employees_rsis by actual_unit as e_list %}
                    {% endif %}

                    {% for list in e_list %}
                        {% if list.list.count > 0 %}
                            <h6>{{ u }}</h6>
                            <table width="100%">
                            {% for e in list.list %}
                                {% if e.dismissed %}
                                    {% if e.pk in form.employees.value %}
                                        <tr class="deleted">
                                            <td><a name="y{{ e.pk }}"></a>
                                                <label for="id_employees_{{ e.pk }}">
                                                    <input type="checkbox"
                                                           name="employees"
                                                           value="{{ e.pk }}"
                                                           id="id_employees_{{ e.pk }}"
                                                           checked="True"
                                                            >{{ e }}
                                                </label>
                                            </td>
                                            <td><span style="color:red;">УВОЛЕН!</span></td>
                                        </tr>
                                    {% endif %}
                                {% else %}
                                <tr>
                                    <td><a name="y{{ e.pk }}"></a>
                                        <label for="id_employees_{{ e.pk }}">
                                            <input type="checkbox"
                                                   name="employees"
                                                   value="{{ e.pk }}"
                                                   id="id_employees_{{ e.pk }}"
                                                    {% if e.pk in form.employees.value %}
                                                        checked="True"
                                                    {% endif %}
                                                    >{{ e }}
                                        </label>
                                    </td>
                                    <td>{{ e.tabel_number }}</td>
                                    <td>{{ e.get_worker_or_rsis_display }}</td>
                                </tr>
                                {% endif %}
                        {% endfor %}
                             </table>
                        {% endif %}
                    {% endfor %}
                {% endfor %}
            </td>
        </tr>
    <tr>
        <td colspan="2"><input class="baton1" style="width:100px;"value="Отправить" type="submit"></td>
    </tr>
    </table>
</form>
    </div>

    {% if object %}
        <div class="grid_3">
            <div class="right_menu">
                <h5>Добавленные</h5>
                {% for e in object.employees.all %}
                    <p><a href="#y{{ e.pk }}">{{ e }}</a></p>
                {% endfor %}
            </div>
        </div>
    {% endif %}
{% endblock %}